//
//  ViewController.m
//  XMFilterView
//
//  Created by mac on 2019/11/21.
//  Copyright © 2019 aishangliguo. All rights reserved.
//

#import "ViewController.h"

// Controller
#import "XMFilterViewController.h"

@interface ViewController () <XMFilterViewControllerDelegate>


@property (nonatomic, strong) XMFilterViewController *filterViewController;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:@"筛选" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(80, 40));
        make.center.mas_equalTo(self.view);
    }];
}

- (void)viewDidMissViewController:(UIViewController *)Controller {
    [UIView animateWithDuration:0.5 animations:^{
        self.filterViewController.filterView.frame = CGRectMake(self.view.bounds.size.width, 0, self.view.bounds.size.width - 44, self.view.bounds.size.height);
        self.filterViewController.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0f];
    } completion:^(BOOL finished) {
        [self.filterViewController removeFromParentViewController];
        [self.filterViewController.view removeFromSuperview];
        self.filterViewController.view = nil;
    }];
    
}

- (void)btnClick:(UIButton *)sender {
    self.filterViewController = [[XMFilterViewController alloc] init];
    [self addChildViewController:self.filterViewController];
    [self.view addSubview:self.filterViewController.view];
    [self.filterViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self.filterViewController didMoveToParentViewController:self];
    self.filterViewController.delegate = self;
}

@end
